package com.qidian.tcba.admin.service.impl;

import com.qidian.tcba.admin.model.dto.district.DistrictListDTO;
import com.qidian.tcba.admin.model.entity.District;
import com.qidian.tcba.admin.service.UserDistrictService;
import com.qidian.tcba.dao.UserDistrictMapper;
import com.qidian.tcba.utils.BeanMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 用户区县表 服务实现类
 * </p>
 *
 * @author 冯永龙
 * @since 2021-07-06
 */
@Service
public class UserDistrictServiceImpl implements UserDistrictService {

    @Autowired
    private UserDistrictMapper userDistrictMapper;

    @Override
    public List<DistrictListDTO> getUserDistrictList(int userId) {
        List<District> districts = userDistrictMapper.getUserDistrictList(userId);
        return BeanMapper.mapList(districts, DistrictListDTO.class);
    }

    @Override
    public int deleteUserDistrictList(int userId) {
        return userDistrictMapper.deleteByUserId(userId);
    }

    @Override
    public int insertUserDistrictList(int userId, List<Integer> userDistrictIds) {
        return userDistrictMapper.insertUserDistrictList(userId, userDistrictIds);
    }

    @Override
    public boolean deleteUserDistrictList(int userId, List<Integer> districtIds) {
        return userDistrictMapper.deleteByDistrictIds(userId, districtIds) >= 1;
    }
}
